<?xml version="1.0" encoding="UTF-8"?>
<model 
    package="App\Model\EComm" 
    baseClass="xPDO\Om\xPDOSimpleObject" 
    platform="mysql" 
    defaultEngine="InnoDB" 
    phpdoc-package="App\Model\EComm" 
    version="3.0">

    <object class="CartItem" table="ecomm_cart_items" extends="xPDO\Om\xPDOSimpleObject">
        <field key="id" dbtype="varchar" precision="40" phptype="string" null="false" />
	    <field key="user_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false"/>
        <field key="product_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false"/>

        <field key="name" dbtype="text" phptype="string" null="true" default=""/>
        <field key="description" dbtype="text" phptype="string" null="true" default=""/>
        <field key="image" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="count" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="1"/>
        <field key="checked" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="1" />

        <field key="createdon" dbtype="datetime" phptype="datetime" />
        <field key="updatedon" dbtype="datetime" phptype="datetime" />
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>
	    
        <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
            <column key="user_id" length="" collation="A" null="false"/>
        </index>
        <index alias="product_id" name="product_id" primary="false" unique="false" type="BTREE">
            <column key="product_id" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="User" class="MODX\Revolution\modUser" local="user_id" foreign="id" owner="foreign" cardinality="one" />
        <aggregate alias="UserProfile" class="MODX\Revolution\modUserProfile" local="user_id" foreign="internalKey" owner="foreign" 
            cardinality="one" />
        <aggregate alias="Product" class="MODX\Revolution\modResource" local="product_id" foreign="id" owner="foreign" 
            cardinality="one" />
    </object>

    <object class="Order" table="ecomm_orders" extends="xPDO\Om\xPDOSimpleObject">
        <field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
        <field key="status_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="address_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="delivery_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="payment_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="payment_status_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
 
        <field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
        <field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
        <field key="updatedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="updatedon" dbtype="datetime" phptype="datetime" null="true" />
        <field key="num" dbtype="varchar" precision="20" phptype="string" null="true" default=""/>
        <field key="sales_tax" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="cart_cost" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="delivery_cost" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="cost" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="weight" dbtype="decimal" precision="13,3" phptype="float" null="true" default="0"/>
        <field key="comment" dbtype="text" phptype="string" null="true" default=""/>
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>

        <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
            <column key="user_id" length="" collation="A" null="false"/>
        </index>
        <index alias="createdby" name="createdby" primary="false" unique="false" type="BTREE">
            <column key="createdby" length="" collation="A" null="false"/>
        </index>
        <index alias="updatedby" name="updatedby" primary="false" unique="false" type="BTREE">
            <column key="updatedby" length="" collation="A" null="false"/>
        </index>
        <index alias="status_id" name="status_id" primary="false" unique="false" type="BTREE">
            <column key="status_id" length="" collation="A" null="false"/>
        </index>
        <index alias="address_id" name="address_id" primary="false" unique="false" type="BTREE">
            <column key="address_id" length="" collation="A" null="false"/>
        </index>
        <index alias="delivery_id" name="delivery_id" primary="false" unique="false" type="BTREE">
            <column key="delivery_id" length="" collation="A" null="false"/>
        </index>
        <index alias="payment_id" name="payment_id" primary="false" unique="false" type="BTREE">
            <column key="payment_id" length="" collation="A" null="false"/>
        </index>
        <index alias="payment_status_id" name="payment_status_id" primary="false" unique="false" type="BTREE">
            <column key="payment_status_id" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Status" class="App\Model\EComm\OrderStatus" local="status_id" foreign="id" owner="foreign"
            cardinality="one" />
        <composite alias="Address" class="App\Model\EComm\OrderAddress" local="address_id" foreign="id" 
            cardinality="one" owner="foreign"/>
        <composite alias="Products" class="App\Model\EComm\OrderProduct" local="id" foreign="order_id" owner="local"
            cardinality="many" />
        <aggregate alias="Delivery" class="App\Model\EComm\Delivery" local="delivery_id" foreign="id" owner="foreign"
            cardinality="one" />
        <aggregate alias="Payment" class="App\Model\EComm\Payment" local="payment_id" foreign="id" owner="foreign" 
            cardinality="one" />
        <aggregate alias="PaymentStatus" class="App\Model\EComm\PaymentStatus" local="payment_status_id" foreign="id" owner="foreign"
            cardinality="one" />
        <aggregate alias="CreatedBy" class="MODX\Revolution\modUser" local="createdby" foreign="internalKey" owner="foreign"
            cardinality="one" />
        <aggregate alias="UpdatedBy" class="MODX\Revolution\modUser" local="updatedby" foreign="internalKey" owner="foreign"
            cardinality="one" />
        <aggregate alias="User" class="MODX\Revolution\modUser" local="user_id" foreign="id" owner="foreign" 
            cardinality="one" />
        <aggregate alias="UserProfile" class="MODX\Revolution\modUserProfile" local="user_id" foreign="internalKey" owner="foreign"
            cardinality="one" />
    </object>

    <object class="OrderStatus" table="ecomm_order_statuses" extends="xPDO\Om\xPDOSimpleObject">
        <field key="name" dbtype="varchar" precision="100" phptype="string" null="false"/>
        <field key="description" dbtype="text" phptype="string" null="true" default="" />
        <field key="color" dbtype="char" precision="6" phptype="string" null="true" default="000000"/>
        <field key="email_user" dbtype="tinyint" precision="1" phptype="integer" null="true" default="0"/>
        <field key="email_manager" dbtype="tinyint" precision="1" phptype="integer" null="true" default="0"/>
        <field key="subject_user" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="subject_manager" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="body_user" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="body_manager" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="active" dbtype="tinyint" precision="1" phptype="integer" null="true" default="1"/>
        <field key="final" dbtype="tinyint" precision="1" phptype="integer" null="true" default="0"/>
        <field key="fixed" dbtype="tinyint" precision="1" phptype="integer" null="true" default="0"/>
        <field key="rank" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="editable" dbtype="tinyint" precision="1" phptype="integer" null="true" default="1"/>

        <index alias="active" name="active" primary="false" unique="false" type="BTREE">
            <column key="active" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Orders" class="App\Model\EComm\Order" local="id" foreign="status_id" owner="local" cardinality="many"/>
    </object>

    <object class="OrderAddress" table="ecomm_order_addresses" extends="xPDO\Om\xPDOSimpleObject">
        <field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false"/>
        <field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
        <field key="updatedon" dbtype="datetime" phptype="datetime" null="true" />
        <field key="receiver" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="phone" dbtype="varchar" precision="20" phptype="string" null="true"/>
        <field key="email" dbtype="varchar" precision="191" phptype="string" null="true"/>
        <field key="country" dbtype="varchar" precision="100" phptype="string" null="true"/>
        <field key="index" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="region" dbtype="varchar" precision="100" phptype="string" null="true"/>
        <field key="city" dbtype="varchar" precision="100" phptype="string" null="true"/>
        <field key="metro" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="street" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="building" dbtype="varchar" precision="10" phptype="string" null="true"/>
        <field key="entrance" dbtype="varchar" precision="10" phptype="string" null="true"/>
        <field key="floor" dbtype="varchar" precision="10" phptype="string" null="true"/>
        <field key="room" dbtype="varchar" precision="10" phptype="string" null="true"/>
        <field key="comment" dbtype="text" phptype="string" null="true"/>
        <field key="text_address" dbtype="text" phptype="string" null="true"/>
        <field key="properties" dbtype="text" phptype="json" null="true" 
            default="{}"/>

        <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
            <column key="user_id" length="" collation="A" null="false"/>
        </index>

        <composite alias="Order" class="App\Model\EComm\Order" local="id" foreign="address_id" owner="foreign"
            cardinality="one" />
        <aggregate alias="User" class="MODX\Revolution\modUser" local="user_id" foreign="id" owner="foreign" cardinality="one"/>
        <aggregate alias="UserProfile" class="MODX\Revolution\modUserProfile" local="user_id" foreign="internalKey" owner="foreign"
            cardinality="one"/>
    </object>

    <object class="OrderProduct" table="ecomm_order_products" extends="xPDO\Om\xPDOSimpleObject">
        <field key="order_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false"/>
        <field key="product_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false"/>
        <field key="name" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="description" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="image" dbtype="varchar" precision="255" phptype="string" null="true"/>
        <field key="tax_rate" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="sales_tax" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="price" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="cost" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="count" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="true" default="1"/>
        <field key="weight" dbtype="decimal" precision="13,3" phptype="float" null="true" default="0"/>
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>

        <index alias="order_id" name="order_id" primary="false" unique="false" type="BTREE">
            <column key="order_id" length="" collation="A" null="false"/>
        </index>
        <index alias="product_id" name="product_id" primary="false" unique="false" type="BTREE">
            <column key="product_id" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Order" class="App\Model\EComm\Order" local="order_id" foreign="id" owner="foreign" 
            cardinality="one"/>
        <aggregate alias="Product" class="MODX\Revolution\modResource" local="product_id" foreign="id" owner="foreign" 
            cardinality="one"/>
    </object>

    <object class="Delivery" table="ecomm_deliveries" extends="xPDO\Om\xPDOSimpleObject">
        <field key="name" dbtype="varchar" precision="255" phptype="string" null="false"/>
        <field key="description" dbtype="text" phptype="string" null="true"/>
        <field key="price" dbtype="varchar" precision="11" phptype="string" null="true" default="0"/>
        <field key="weight_price" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="distance_price" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="free_delivery_amount" dbtype="decimal" precision="12,2" phptype="float" null="true" default="0"/>
        <field key="logo" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="rank" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="active" dbtype="tinyint" precision="1" phptype="integer" null="true" default="1"/>
        <field key="class" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>

        <index alias="active" name="active" primary="false" unique="false" type="BTREE">
            <column key="active" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Orders" class="App\Model\EComm\Order" local="id" foreign="delivery_id" owner="local" cardinality="many"/>
    </object>

    <object class="Payment" table="ecomm_payments" extends="xPDO\Om\xPDOSimpleObject">
        <field key="name" dbtype="varchar" precision="255" phptype="string" null="false"/>
        <field key="description" dbtype="text" phptype="string" null="true"/>
        <field key="price" dbtype="varchar" precision="11" phptype="string" null="true" default="0"/>
        <field key="logo" dbtype="varchar" precision="255" phptype="string" null="true" default=""/>
        <field key="rank" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="active" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="true" default="1"/>
        <field key="class" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>

        <index alias="active" name="active" primary="false" unique="false" type="BTREE">
            <column key="active" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Orders" class="App\Model\EComm\Order" local="id" foreign="payment" owner="local" cardinality="many"/>
    </object>

    <object class="PaymentStatus" table="ecomm_payment_statuses" extends="xPDO\Om\xPDOSimpleObject">
        <field key="name" dbtype="varchar" precision="100" phptype="string" null="false"/>
        <field key="description" dbtype="text" phptype="string" null="true"/>
        <field key="color" dbtype="char" precision="6" phptype="string" null="true" default="000000"/>
        <field key="rank" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="0"/>
        <field key="active" dbtype="tinyint" precision="1" phptype="boolean" null="true" default="1"/>
        <field key="class" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="properties" dbtype="text" phptype="json" null="true" default="{}"/>
	    
        <index alias="active" name="active" primary="false" unique="false" type="BTREE">
            <column key="active" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="Order" class="App\Model\EComm\Order" local="id" foreign="payment_status_id" cardinality="one" owner="foreign"/>
    </object>

    <object class="ProductFavorite" table="ecomm_product_favorites" extends="xPDO\Om\xPDOSimpleObject">
	    <field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false"/>
	    <field key="product_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false"/>

        <field key="timestamp" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP"/>
  		<field key="properties" dbtype="text" phptype="json" null="true" default="{}" />
		
        <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
            <column key="user_id" length="" collation="A" null="false"/>
        </index>
        <index alias="product_id" name="product_id" primary="false" unique="false" type="BTREE">
            <column key="product_id" length="" collation="A" null="false"/>
        </index>
      
        <aggregate alias="User" class="MODX\Revolution\modUser" local="user_id" foreign="id" owner="foreign" 
            cardinality="one" />
        <aggregate alias="UserProfile" class="MODX\Revolution\modUserProfile" local="user_id" foreign="internalKey" owner="foreign" 
            cardinality="one" />
        <aggregate alias="Product" class="MODX\Revolution\modResource" local="product_id" foreign="id" owner="foreign" 
            cardinality="one"/>        
    </object>
</model>